<template>
  <div class="person-container">
    <el-card class="person-card-left">
      <div class="person-card-left-title">
        <div class="block">
          <el-avatar shape="circle" :size="100" :src="userStore.userInfo.avatar" />
          <h2>{{ userStore.$state.personInfo.name }}</h2>
          <p>{{ userStore.$state.personInfo.description }}</p>
          <el-button type="primary" icon="Apple">Follow Me</el-button>
        </div>
      </div>
      <!-- 描述 -->
      <div class="person-card-left-content">
        <div class="info-item">
          <el-icon><Apple /></el-icon>
          <span>前端从业者</span>
        </div>
        <div class="info-item">
          <el-icon><Calendar /></el-icon>
          <span>1999/06/10</span>
        </div>
        <div class="info-item">
          <el-icon><Male /></el-icon>
          <span>{{ userStore.$state.personInfo.sex }}</span>
        </div>
        <div class="info-item">
          <el-icon><Office /></el-icon>
          <span>集团-事业部-技术部</span>
        </div>
        <div class="info-item">
          <el-icon><Location /></el-icon>
          <span>中国.广东省.佛山市</span>
        </div>
        <div class="info-item">
          <el-icon><Connection /></el-icon>
          <span>javascript, html, css, vue, node, 前端性能优化</span>
        </div>
      </div>
      <el-divider />
      <div class="person-card-left-footer">
        <div>个性标签</div>
        <div>
          <el-tag
            type="primary"
            v-for="(item, index) in userStore.$state.personInfo.tagList"
            :key="index"
            class="tag"
            >{{ item }}</el-tag
          >
        </div>
      </div>
    </el-card>
    <el-card class="person-card-right">
      <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
        <el-tab-pane label="基本信息" name="first">
          <el-row>
            <el-col :span="12">
              <el-form
                label-width="100px"
                label-position="top"
                class="user-info"
                :model="personData"
              >
                <el-form-item label="姓名">
                  <el-input v-model="personData.name" prop="name"></el-input>
                </el-form-item>
                <el-form-item label="昵称" prop="adv">
                  <el-input v-model="personData.adv"></el-input>
                </el-form-item>
                <el-form-item label="性别">
                  <el-select v-model="personData.sex" placeholder="男">
                    <el-option label="保密" value="空"></el-option>
                    <el-option label="男" value="男"></el-option>
                    <el-option label="女" value="女"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="个人简介" prop="description">
                  <el-input type="textarea" :rows="4" v-model="personData.description"></el-input>
                </el-form-item>
                <el-form-item label="标签" prop="tagList">
                  <el-tag
                    type="primary"
                    closable
                    v-for="(item, index) in userStore.personInfo.tagList"
                    :key="index"
                    class="tag"
                    @close="handleClose(item)"
                    >{{ item }}</el-tag
                  >
                  <el-input
                    v-model="tagInput"
                    placeholder=""
                    class="tag-input"
                    clearable
                    ref="InputRef"
                    v-if="showInput"
                    size="small"
                    @blur="inputBlur"
                  />
                  <el-button size="small" v-else @click="addTag">添加</el-button>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="saveInfo">保存</el-button>
                </el-form-item>
              </el-form>
            </el-col>
            <el-col :span="12">
              <el-upload
                class="upload-demo"
                drag
                action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
                multiple
              >
                <el-icon class="el-icon--upload"><upload-filled /></el-icon>
                <div class="el-upload__text">Drop file here or <em>click to upload</em></div>
                <template #tip>
                  <div class="el-upload__tip">jpg/png files with a size less than 500kb</div>
                </template>
              </el-upload>
              <el-button type="primary">点击上传头像</el-button>
            </el-col>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="联系方式" name="second">联系方式</el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
  <Footer></Footer>
</template>

<script setup lang="ts">
import { ref, nextTick, reactive } from "vue";
import Footer from "@/components/reuse/footer.vue";
import { ElMessage, InputInstance } from "element-plus";
import { UploadFilled, Apple } from "@element-plus/icons-vue";
import { useUserStore } from "@/store/user";
const personData = reactive({
  name: "",
  adv: "",
  description: "",
  tagList: [],
  sex: "",
});
const activeName = ref("first");
const tagInput = ref("");
const showInput = ref(false);
const userStore = useUserStore();
const InputRef = ref<InputInstance>();
const handleClick = (tab: string) => {
  console.log(tab);
};
// 添加标签
const addTag = () => {
  // tagList.value.push(tagInput.value);
  // tagInput.value = "";
  showInput.value = true;
  nextTick(() => {
    InputRef.value!.input!.focus();
  });
};
//
const inputBlur = () => {
  !showInput.value;
  userStore.$state.personInfo.tagList.push(tagInput.value);
  showInput.value = false;
  tagInput.value = "";
};
const handleClose = (i: string) => {
  const index = userStore.$state.personInfo.tagList.indexOf(i);
  if (index > -1) {
    userStore.$state.personInfo.tagList.splice(index, 1);
  }
};
//
const saveInfo = () => {
  userStore.$patch((state) => {
    state.personInfo = personData;
    ElMessage({
      type: "success",
      message: "模拟保存成功",
    });
  });
};
</script>

<style scoped>
.person-container {
  height: calc(100vh - 100px);
  display: flex;
  gap: 20px;
}

/* 左侧卡片样式 */
.person-card-left {
  width: 40%;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.person-card-left-title {
  text-align: center;
  padding: 30px 20px;
}

.block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.block h2 {
  margin: 16px 0 0;
  font-size: 24px;
  font-weight: 600;
  color: var(--el-text-color-primary);
}

.block p {
  margin: 0;
  color: var(--el-text-color-secondary);
  font-size: 14px;
  line-height: 1.6;
}

.block .el-button {
  margin-top: 8px;
  width: 140px;
  border-radius: 20px;
  transition: all 0.3s ease;
}

.block .el-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.el-divider {
  margin: 24px 0;
  border-color: rgba(255, 255, 255, 0.1);
}
.person-card-left-content {
  padding: 0 30px;
}

.info-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  color: var(--el-text-color-regular);
  transition: all 0.3s ease;
}

.info-item:hover {
  transform: translateX(5px);
  color: var(--el-text-color-primary);
}

.info-item .el-icon {
  font-size: 18px;
  color: var(--el-text-color-secondary);
  background: rgba(255, 255, 255, 0.1);
  padding: 8px;
  border-radius: 8px;
  transition: all 0.3s ease;
}

.info-item:hover .el-icon {
  background: var(--el-color-primary-light-9);
  color: var(--el-color-primary);
  transform: scale(1.1);
}

.info-item span {
  font-size: 14px;
  line-height: 1.6;
}

/* 最后一项（技能标签）的特殊样式 */
.info-item:last-child span {
  flex: 1;
  word-break: break-word;
  line-height: 1.8;
}

.person-card-left-footer {
  padding: 0 20px 20px;
}

.person-card-left-footer > div:first-child {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 16px;
  color: var(--el-text-color-primary);
}

.tag {
  margin: 4px;
  border-radius: 16px;
  padding: 6px 12px;
  transition: all 0.3s ease;
}

.tag:hover {
  transform: translateY(-2px);
}

/* 右侧卡片样式 */
.person-card-right {
  flex: 1;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* 头像动画 */
.el-avatar {
  transition: transform 0.3s ease;
  border: 4px solid rgba(255, 255, 255, 0.1);
}

.el-avatar:hover {
  transform: scale(1.05);
}

/* 标签输入框样式 */
.tag-input {
  margin: 8px;
  width: 120px;
}

/* 确保深色主题下的可见性 */
:deep(.el-card) {
  background: transparent;
  border: none;
  box-shadow: none;
}
</style>
